﻿
//#define RGB_标定_上灯  
#define RGB_标定_下灯


using IdeaOptics;
using MathDriver.CIE_Source;
using MathDriver.CIE_Standard;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Math = MathDriver.Math;
using USB2XXX;
using System.Security.Cryptography;
using System.Xml.Linq;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Globalization;
using System.Runtime.ConstrainedExecution;
using System.Linq;
using System.Threading.Tasks;


namespace RGB_Sampling
{
    public enum ColorName
    {
        Red = 0,
        Green = 1,
        Blue = 2,
        Color1 = 3,
        Color2 = 4,
        Color3 = 5,
        Color4 = 6,
        Color5 = 7,
        Color6 = 8,
        Sleep = 9,
        Color256 = 10,
    }
    public partial class Form1 : Form
    {
        private bool Btn_Result = true;
        private Stopwatch sw;

        //光谱界面相关
        private DataMode[] dataMode = new DataMode[12];
        private DataMode[] dataMode_2 = new DataMode[12];

        //光谱仪相关
        ICIESource Led_Source;
        ICIEStandard Standard;
        Math math;
        Wrapper wrapper;
        /// <summary>
        /// 采样默认 50, 采样次数
        /// </summary>
        int sample_count = 10;
        double Threshold = 0.01; //阈值
        /// <summary>
        /// units: ms, 积分时间
        /// </summary>
        double integral = 3;  //12_R: 0.70
        /// <summary>
        /// 设置光谱仪平均次数
        /// </summary>
        int aver = 20;

        //Txt相关
        /// <summary>
        /// 从Check_View.txt读取的视见函数
        /// </summary>
        List<double> View_Txt = new List<double>();
        /// <summary>
        /// 从SN20224701_L.txt读取编号为20224701的光谱仪的补偿值
        /// </summary>
        List<double> WaveOffset_L_Txt = new List<double>();
        /// L_RED.txt读取编号为20224701的光谱仪红色的补偿值
        /// </summary>
        List<double> SET_L_RED_Txt = new List<double>();
        /// L_GREEN.txt读取编号为20224701的光谱仪绿色的补偿值
        /// </summary>
        List<double> SET_L_GREEN_Txt = new List<double>();
        /// L_BLUE.txt读取编号为20224701的光谱仪蓝色的补偿值
        /// </summary>
        List<double> SET_L_BLUE_Txt = new List<double>();
        /// <summary>
        /// 从SN20230901_R.txt读取编号为20230901的光谱仪的补偿值
        /// </summary>
        List<double> WaveOffset_R_Txt = new List<double>();
        /// R_RED.txt读取编号为20230901的光谱仪的红色补偿值
        /// </summary>
        List<double> SET_R_RED_Txt = new List<double>();
        /// R_GREEN.txt读取编号为20230901的光谱仪的绿色补偿值
        /// </summary>
        List<double> SET_R_GREEN_Txt = new List<double>();
        /// R_BLUE.txt读取编号为20230901的光谱仪的蓝色补偿值
        /// </summary>
        List<double> SET_R_BLUE_Txt = new List<double>();

        List<double> WaveLength_Txt = new List<double>(); //波长
        /// <summary>
        /// 从Check.txt读取的校正系数
        /// </summary>
        List<double> Factor_Txt = new List<double>();
        //黑校准相关
        List<double> WaveLength_Black = new List<double>(); //波长
        /// <summary>
        /// 黑校准的光谱
        /// </summary>
        List<double> Spectrum_Black = new List<double>();
        List<double> Spectrum_Black_2 = new List<double>();

        //光谱计算结果相关
        private List<double> wavelengths = new List<double>(); //可见波的波长集合
        private List<double> wavelengths_2 = new List<double>(); //可见波的波长集合
        Dictionary<ColorName, double[]> xyz = new Dictionary<ColorName, double[]>(); //RGB波长的色坐标 
        Dictionary<ColorName, double[]> xyz_2 = new Dictionary<ColorName, double[]>(); //RGB波长的色坐标 
        Dictionary<ColorName, double> T_Relative = new Dictionary<ColorName, double>(); //RGB波长的相对光通量 
        Dictionary<ColorName, double> T_Relative_2 = new Dictionary<ColorName, double>(); //RGB波长的相对光通量 

        //阈值 判断标准
        Threshold_Reference threshold_Ref = new Threshold_Reference();


        //线程相关
        Thread thread = null;

        /// <summary>
        /// 256种颜色序号
        /// </summary>
        public byte ColorSeq { get; private set; }

        //图莫斯Lin通信 相关参数
        Int32 DevHandle = 0;
        Byte LINIndex = 1;
        int hard_hexValue = 0;
        int hexValue = 0;
        int Pass_num = 0;
        int Error_num = 0;
        int touch_flag = 0;

        byte FL_touch_flag = 0;
        byte FR_touch_flag = 0;
        byte RL_touch_flag = 0;
        byte RR_touch_flag = 0;

        public Form1()
        {
            InitializeComponent();
            USB_DEVICE.DEVICE_INFO DevInfo = new USB_DEVICE.DEVICE_INFO();
            Int32[] DevHandles = new Int32[20];
            bool state;
            Int32 DevNum, ret = 0;
            string dllFilePath = "USB2XXX.dll";
            if (!File.Exists(dllFilePath))
            {
                Console.WriteLine("请先将USB2XXX.dll和libusb-1.0.dll文件复制到exe程序文件输出目录下!");
                Console.WriteLine("dll文件在‘usb2can_lin_pwm_example/sdk/libs/windows’目录下！");
                Console.WriteLine("程序是32位的就复制‘x86’目录下文件，程序是64位的就复制‘x86_64’目录下文件！");
                return;
            }
            //扫描查找设备
            DevNum = USB_DEVICE.USB_ScanDevice(DevHandles);
            if (DevNum > 2)
            {
                MessageBox.Show("只支持一个图莫斯驱动。");
                return;
            }
            if (DevNum == 0)
            {
                MessageBox.Show("没接上图莫斯驱动。");
                return;
            }
            DevHandle = DevHandles[0];
            //打开设备
            state = USB_DEVICE.USB_OpenDevice(DevHandle);
            if (!state)
            {
                Console.WriteLine("Open device error!");
                return;
            }
            else
            {
                Console.WriteLine("Open device success!");
            }
            //获取固件信息
            StringBuilder FuncStr = new StringBuilder(256);
            state = USB_DEVICE.DEV_GetDeviceInfo(DevHandle, ref DevInfo, FuncStr);
            if (!state)
            {
                Console.WriteLine("Get device infomation error!");
                return;
            }
            else
            {
                Console.WriteLine("Firmware Info:");
                Console.WriteLine("    Name:" + Encoding.Default.GetString(DevInfo.FirmwareName));
                Console.WriteLine("    Build Date:" + Encoding.Default.GetString(DevInfo.BuildDate));
                Console.WriteLine("    Firmware Version:v{0}.{1}.{2}", (DevInfo.FirmwareVersion >> 24) & 0xFF, (DevInfo.FirmwareVersion >> 16) & 0xFF, DevInfo.FirmwareVersion & 0xFFFF);
                Console.WriteLine("    Hardware Version:v{0}.{1}.{2}", (DevInfo.HardwareVersion >> 24) & 0xFF, (DevInfo.HardwareVersion >> 16) & 0xFF, DevInfo.HardwareVersion & 0xFFFF);
                Console.WriteLine("    Functions:" + DevInfo.Functions.ToString("X8"));
                Console.WriteLine("    Functions String:" + FuncStr);
            }
            //初始化配置LIN
            ret = USB2LIN_EX.LIN_EX_Init(DevHandle, LINIndex, 19200, USB2LIN_EX.LIN_EX_MASTER);//初始化为主机
            if (ret != USB2LIN_EX.LIN_EX_SUCCESS)
            {
                Console.WriteLine("Config LIN failed!");
                MessageBox.Show("LIN打开失败", "提示");
            }
            else
            {
                Console.WriteLine("Config LIN Success!");
            }

            Lin_MasterWrite(GetUartCmd(ColorName.Sleep));
        }

        bool panVersion()
        {
            byte[] param1 = null;
            byte[] param2 = null;
            byte[] param3 = null;
            byte[] param4 = null;

            string hard_hexString = Hard_Version.Text;
            string hexString = Version.Text;


            // 验证并转换16进制字符串
            if (IsHexString(hard_hexString))
            {
                // 转换为数值
                hard_hexValue = Convert.ToInt32(hard_hexString, 16);
            }
            else
            {
                MessageBox.Show("请输入有效的16进制值。");
                Version.Text = ""; // 清除无效输入
                Version.Focus(); // 重新聚焦文本框
            }
            // 验证并转换16进制字符串
            if (IsHexString(hexString))
            {
                // 转换为数值
                hexValue = Convert.ToInt32(hexString, 16);
            }
            else
            {
                MessageBox.Show("请输入有效的16进制值。");
                Version.Text = ""; // 清除无效输入
                Version.Focus(); // 重新聚焦文本框
            }

            var hard_txt = hard_hexValue;
            var txt = hexValue; //Convert.ToInt16(Version.Text);        //读输入版本号
            param1 = new byte[] { 0xb4, 0x02, 0x40, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09 }; //顶空图莫斯测试指令（红色点亮）
            param2 = new byte[] { 0x61, 0xF8, 0x5F, 0x08, 0xF0, 0xBF, 0x10, 0x00, 0x00, 0x7D }; //顶空图莫斯测试指令（白色点亮）
            param3 = new byte[] { 0xD8, 0x00, 0x1E, 0x1E, 0x1E, 0x1E, 0x00, 0x00, 0x00, 0xAE }; //顶空图莫斯测试指令（阅读灯点亮）
            param4 = new byte[] { 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27 }; //顶空图莫斯测试指令（阅读灯熄灭）

            byte[] Version_Read_Buffer = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            byte Hard_Version_Read = 0;
            byte Version_Read = 0;
            byte global_voltage = 0; //AD检测电压
            byte global_current_1 = 0; //AD检测电流
            byte global_current_2 = 0; //AD检测电流
            byte global_ntc_l = 0; //AD检测温度
            byte global_ntc_r = 0; //AD检测温度
            Lin_MasterWrite(param1);

            for (int i = 0; i < 10; i++)
            { //唤醒
                Lin_MasterWrite(param1);
                Lin_MasterWrite(param2);
                Lin_MasterWrite(param3);
                Thread.Sleep(400);
            }
            Thread.Sleep(10);
            for (int i = 0; i < 5; i++)
            {
                Lin_MasterWrite(param2);
                Lin_MasterWrite(param3);
                USB2LIN_EX.LIN_EX_MasterRead(DevHandle, LINIndex, 0x32, Version_Read_Buffer);
                Hard_Version_Read = Version_Read_Buffer[0];
                Version_Read = Version_Read_Buffer[1];
                global_voltage = Version_Read_Buffer[3];
                global_current_1 = Version_Read_Buffer[4];
                global_current_2 = Version_Read_Buffer[5];
                global_ntc_l = Version_Read_Buffer[6];
                global_ntc_r = Version_Read_Buffer[7];
                Thread.Sleep(10);
            }
            Thread.Sleep(10);
            Lin_MasterWrite(param4);
            Thread.Sleep(10);
            if (global_voltage < 80)
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("电压过小！");
                return false;
            }
            else if (global_voltage > 110)
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("电压过大！");
                return false;
            }
            else
            {
                View.Text = String.Concat(View.Text, "电压正常", "\r\n");
            }

            if (global_current_1 < 12)
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("前阅读灯电流过小！");
                return false;
            }
            else if (global_current_1 > 30)
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("前阅读灯电流过大！");
                return false;
            }
            else
            {
                View.Text = String.Concat(View.Text, "前阅读灯电流正常", "\r\n");
            }

            if (global_current_2 < 7)
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("后阅读灯电流过小！");
                return false;
            }
            else if (global_current_2 > 20)
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("后阅读灯电流过大！");
                return false;
            }
            else
            {
                View.Text = String.Concat(View.Text, "后阅读灯电流正常", "\r\n");
            }

            if (global_ntc_l < 80)
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("左NTC温度过高！");
                return false;
            }
            else if (global_ntc_l > 200)
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("左NTC故障！");
                return false;
            }
            else
            {
                View.Text = String.Concat(View.Text, "左NTC温度正常", "\r\n");
            }

            if (global_ntc_r < 80)
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("右NTC温度过高！");
                return false;
            }
            else if (global_ntc_r > 200)
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("右NTC故障！");
                return false;
            }
            else
            {
                View.Text = String.Concat(View.Text, "右NTC温度正常", "\r\n");
            }

            if (Hard_Version_Read == hard_txt)
            {
                btn_Result.BackColor = Color.Transparent;
                btn_Result.Text = "Version_Ture";
                View.Text = String.Concat(View.Text, "硬件版本号正确", "\r\n");
            }
            else
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("硬件版本号不正确！", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            if (Version_Read == txt)
            {
                btn_Result.BackColor = Color.Green;
                btn_Result.Text = "PASS";
                View.Text = String.Concat(View.Text, "软件版本号正确", "\r\n");
                return true;
            }
            else
            {
                btn_Result.BackColor = Color.Red;
                btn_Result.Text = "NG";
                MessageBox.Show("软件版本号不正确！", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
        }

        void Touch_task()
        {
            byte[] Feedback_Buffer = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            byte[] param = new byte[] { 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //顶空图莫斯测试指令（阅读灯点亮） 
            Task.Text = String.Concat( "请触摸左前阅读灯", "\r\n");
            Task.Refresh();
            while (touch_flag!=4)
            {
                USB2LIN_EX.LIN_EX_MasterRead(DevHandle, LINIndex, 0x22, Feedback_Buffer);
                if((Feedback_Buffer[0]&0x40)!=0 && FL_touch_flag!=1 && touch_flag == 0)
                {
                    Task.Text = String.Concat("左前阅读灯触摸正常", "\r\n");
                    Task.Refresh();
                    FL_touch_flag = 1;
                    Thread.Sleep(200);
                    Task.Text = String.Concat("请触摸右前阅读灯", "\r\n");
                    Task.Refresh();
                }
                if ((Feedback_Buffer[1]&0x40)!=0 && FR_touch_flag != 1 && touch_flag == 1)
                {
                    Task.Text = String.Concat("右前阅读灯触摸正常", "\r\n");
                    Task.Refresh();
                    FR_touch_flag = 1;
                    Thread.Sleep(200);
                    Task.Text = String.Concat("请触摸左后阅读灯", "\r\n");
                    Task.Refresh();
                }
                if ((Feedback_Buffer[2] & 0x40) != 0 && RL_touch_flag != 1 && touch_flag == 2)
                {
                    Task.Text = String.Concat("左后阅读灯触摸正常", "\r\n");
                    Task.Refresh();
                    RL_touch_flag = 1;
                    Thread.Sleep(200);
                    Task.Text = String.Concat("请触摸右后阅读灯", "\r\n");
                    Task.Refresh();
                }
                if ((Feedback_Buffer[3] & 0x40) != 0 && RR_touch_flag != 1 && touch_flag == 3)
                {
                    Task.Text = String.Concat("阅读灯触摸测试完毕", "\r\n");
                    Task.Refresh();
                    RR_touch_flag = 1;
                    Thread.Sleep(200);
                }
                touch_flag = FL_touch_flag + FR_touch_flag + RL_touch_flag + RR_touch_flag;
                param[2] = (byte)(0x1E * FL_touch_flag);
                param[3] = (byte)(0x1E * FR_touch_flag);
                param[4] = (byte)(0x1E * RL_touch_flag);
                param[5] = (byte)(0x1E * RR_touch_flag);
                Lin_MasterWrite(param);
                Thread.Sleep(50);
             }
            FL_touch_flag = 0;
            FR_touch_flag = 0;
            RL_touch_flag = 0;
            RR_touch_flag = 0;
            touch_flag = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.DoEvents();
            button1.BackColor = Color.Yellow;
            button1.Text = "测试中";
            button1.Enabled = false;
            Task.Clear();
            View.Clear();
            Touch_task();
            Task.Text = String.Concat("数据测量中...", "\r\n");
            Task.Refresh();
            bool Version_flag = panVersion();
            if (Version_flag)
            {
                Pass_num++;
                button1.Enabled = false;
            }
            else
            {
                Error_num++;
            }
            Task.Text = String.Concat("测试完成", "\r\n");
            Task.Refresh();
            View.Text = String.Concat(View.Text, "\r\n");
            View.Text = String.Concat(View.Text, "已完成次数:", Pass_num.ToString(), "\r\n");
            View.Text = String.Concat(View.Text, "不良次数:", Error_num.ToString(), "\r\n");

            Application.DoEvents();
            button1.Enabled = true;
            button1.BackColor = Color.AntiqueWhite;
            button1.Text = "测试";
        }
        private byte[] GetUartCmd(ColorName color)
        {
            byte[] param = null;

            if (color == ColorName.Red)
            {
                //param = new byte[] { 0x00, 0x55, 0xb4, 0x01, 0x40, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a }; //顶空串口测试指令
                param = new byte[] { 0xb4, 0x01, 0x40, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a }; //顶空图莫斯测试指令
            }
            else if (color == ColorName.Green)
            {
                //param = new byte[] { 0x00, 0x55, 0xb4, 0x01, 0x40, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0a }; //顶空串口测试指令
                param = new byte[] { 0xb4, 0x01, 0x40, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0a }; //顶空图莫斯测试指令
            }
            else if (color == ColorName.Blue)
            {
                //param = new byte[] { 0x00, 0x55, 0xB4, 0x01, 0x40, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x0a };
                param = new byte[] { 0xB4, 0x01, 0x40, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x0a };
            }

            else if (color == ColorName.Color1)
            {
                //param = new byte[] { 0x00, 0x55, 0xB4, 0X01 ,0X40 ,0X00 ,0X00 ,0X00 ,0X72 ,0X00 ,0X00, 0x97 };
                param = new byte[] { 0xB4, 0X01, 0X40, 0X00, 0X00, 0X00, 0X72, 0X00, 0X00, 0x97 };
            }
            else if (color == ColorName.Color2)
            {
                //param = new byte[] { 0x00, 0x55, 0xB4, 0X01, 0X40, 0X00, 0X00, 0X00, 0XB9, 0X00, 0X00, 0x50 };
                param = new byte[] { 0xB4, 0X01, 0X40, 0X00, 0X00, 0X00, 0XB9, 0X00, 0X00, 0x50 };
            }
            else if (color == ColorName.Color3)
            {
                //param = new byte[] { 0x00, 0x55, 0xB4 , 0X01, 0X40, 0X00, 0X00, 0X00, 0X55, 0X00, 0X00, 0xB4 };
                param = new byte[] { 0xB4, 0X01, 0X40, 0X00, 0X00, 0X00, 0X55, 0X00, 0X00, 0xB4 }; 
            }
            else if (color == ColorName.Color4)
            {
                //param = new byte[] { 0x00, 0x55, 0xB4, 0X01, 0X40, 0X00, 0X00, 0X00, 0XF3, 0X00, 0X00, 0x16 };
                param = new byte[] { 0xB4, 0X01, 0X40, 0X00, 0X00, 0X00, 0XF3, 0X00, 0X00, 0x16 };
            }
            else if (color == ColorName.Color5)
            {
                //param = new byte[] { 0x00, 0x55, 0xB4, 0X01, 0X40, 0X00, 0X00, 0X00, 0XD0, 0X00, 0X00, 0x39 };
                param = new byte[] { 0xB4, 0X01, 0X40, 0X00, 0X00, 0X00, 0XD0, 0X00, 0X00, 0x39 };
            }
            else if (color == ColorName.Color6)
            {
                //param = new byte[] { 0x00, 0x55, 0xB4, 0X01, 0X40, 0X00, 0X00, 0X00, 0X0B, 0X00, 0X00, 0xFE };
                param = new byte[] { 0xB4, 0X01, 0X40, 0X00, 0X00, 0X00, 0X0B, 0X00, 0X00, 0xFE };
            }
            else if (color == ColorName.Sleep)
            {
                param = new byte[] { 0x3C, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 };
            }

            return param;
        }

        #region 串口相关的所有函数

        /// <summary>
        /// 通过 图莫斯 发送Lin数据
        /// </summary>
        private void Lin_MasterWrite(byte[] DataBuffer)
        {
            byte[] temp = new byte[DataBuffer.Length - 1];
            for (int i = 1; i < DataBuffer.Length; i++)
            {
                temp[i - 1] = DataBuffer[i];
            }
            Lin_MasterWrite(DataBuffer[0], temp);
        }
        private void Lin_MasterWrite(byte pid, byte[] DataBuffer)
        {
            Byte checkType = USB2LIN_EX.LIN_EX_CHECK_STD;
            if (pid == 0x3c) checkType = USB2LIN_EX.LIN_EX_CHECK_STD;
            else checkType = USB2LIN_EX.LIN_EX_CHECK_EXT;
            //唤醒设备
            var ret = USB2LIN_EX.LIN_EX_MasterWrite(DevHandle, LINIndex, pid, DataBuffer, (byte)DataBuffer.Length, checkType);
            if (ret != USB2LIN_EX.LIN_EX_SUCCESS)
            {
                Console.WriteLine("Write LIN failed!");
                return;
            }
            else
            {
                Console.WriteLine("Write LIN Success!");
            }
        }

#endregion


        private void label4_Click(object sender, EventArgs e)
        {

        }

        void button3_Click()
        {
           
        }


        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btn_Result_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            // 允许数字和十六进制字符 A-F
            if (!char.IsDigit(e.KeyChar) && !(char.ToUpper(e.KeyChar) >= 'A' && char.ToUpper(e.KeyChar) <= 'F'))
            {
                e.Handled = true;
            }
            //if (e.KeyChar == (char)Keys.Enter)
            //{
            //    // 触发按钮点击事件
            //    button1.PerformClick();

            //}
        }

        private void textBox1_Leave_1(object sender, EventArgs e)
        {
          
        }

        // 检查是否为有效的16进制字符串
        private bool IsHexString(string str)
        {
            return int.TryParse(str, NumberStyles.HexNumber, null, out _);
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }
    }
}
